home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group00a.txt
/
000018_icon-group-sender _Tue Feb 1 11:06:54 2000.msg
< prev
next >
Wrap
Internet Message Format
|
2001-01-03
|
2KB
Return-Path: <icon-group-sender>
Received: (from root@localhost)
by baskerville.CS.Arizona.EDU (8.9.1a/8.9.1) id LAA00037
for icon-group-addresses; Tue, 1 Feb 2000 11:05:33 -0700 (MST)
Message-Id: <200002011805.LAA00037@baskerville.CS.Arizona.EDU>
From: dgamey@ca.ibm.com
X-Lotus-FromDomain: IBMCA@IBMUS
To: icon-group@optima.CS.Arizona.EDU
cc: "Charles Hethcoat" <CHETHCOA@oss.oceaneering.com>
Date: Mon, 31 Jan 2000 21:54:54 -0500
Subject: Re: Updating array parameters in Icon (a mini-dissertation)
Content-Disposition: inline
Errors-To: icon-group-errors@optima.CS.Arizona.EDU
Status: RO
Charles,
You are correct about icon's pointer semantics. In (my paraphrase of)
your example:
procedure main()
x := []
method1( x )
method2( x )
end
procedure method1(x)
x := [&e]
return
end
procedure method2(x)
put(x, &pi)
return
end
You should expect that x will not be modified by method1. The reason for
this can be illustrated with the following:
procedure main()
y := x := [1,2,3]
y[2] := 5
if x[2] = 5 then write("Changed") else write("Unchanged")
end
This program will write "Changed"
In both method1 and method2, local/parameter x is assigned to main's x.
In method1, local x is then assigned to a new list (creating a new
structure in the block region).
In method2, the contents of x are changed. Since local x and main's x
"point" to the same structure block (i.e. are identical === ), then the
contents of that block are changed.
In both cases, the local value of x is destroyed upon return.
You'll find this behaviour consistent amongst the structure objects that
get allocated in the block region (lists, sets, tables, records). Numbers
and strings behave differently. (I'm not sure about csets, but I suspect
they behave much like strings and numbers.)
David Gamey